//
//  BPNavigationController.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/7/27.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "BPNavigationController.h"
#import "BPNavButtonView.h"

@interface BPNavigationController ()

@end

@implementation BPNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

+ (void)initialize
{
    [self setupBarButtonItemTheme];
    [self setupNavigationbBarTheme];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+ (void)setupNavigationbBarTheme
{
    UINavigationBar* apperance = [UINavigationBar appearance];
    
    NSMutableDictionary* textarrys = [NSMutableDictionary dictionary];
    textarrys[NSForegroundColorAttributeName] = BPFenHongColor;
    textarrys[NSFontAttributeName] = BPNavigationTitleFont;
    [apperance setTitleTextAttributes:textarrys];
    
}
+ (void)setupBarButtonItemTheme
{
    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    /**设置文字属性**/
    // 设置普通状态的文字属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = BPFenHongColor;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [appearance setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    // 设置高亮状态的文字属性
    NSMutableDictionary *highTextAttrs = [NSMutableDictionary dictionaryWithDictionary:textAttrs];
    highTextAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [appearance setTitleTextAttributes:highTextAttrs forState:UIControlStateHighlighted];
    
    // 设置不可用状态(disable)的文字属性
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionaryWithDictionary:textAttrs];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [appearance setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
    
    /**设置背景**/
    //技巧: 为了让某个按钮的背景消失, 可以设置一张完全透明的背景图片
    [appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //判断是否栈底控制器（最先push进来的控制器）
    if (self.viewControllers.count > 0) {
        //viewController.hidesBottomBarWhenPushed = YES;
        //设置导航栏按钮
       // viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithButtonName:@"返回" tatget:self action:@selector(back)];
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"返回" highImageName:@"返回" target:self action:@selector(back)];
    }
    [super pushViewController:viewController animated:YES];
}
- (void)back
{
    [self popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
